package com.cqut.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import com.cqut.dto.LimitShowDTO;
import com.cqut.service.IWorkManagementService;
import com.cqut.util.ResponseUtil;

@RestController
@RequestMapping("/api/workManagement")
public class WorkManagementController {
	
	  @Resource(name="workManagementService")
	  private IWorkManagementService workManagementService;

	  /**
	   * 初始化列表
	   * @param limitShowDTO
	   * @param errors
	   * @return
	   */
	   @RequestMapping(value = "/list", method = RequestMethod.GET)
	   public ResponseEntity<String> list(

			String competitionName,

			String phaseName,

			String competitionProcess,
	
			String submission,
	   		@Validated
	   		LimitShowDTO limitShowDTO, BindingResult errors) {
		   if(errors.hasErrors())
	           return ResponseUtil.getResponseEntityWhenInvalidReqParams();
	        
	       Map<String, Object> result = new HashMap<String, Object>();
	       
	       System.out.println(competitionName);
	       System.out.println(phaseName);
	       System.out.println(competitionProcess);
	       System.out.println(submission);
	       
	       List<Map<String, Object>> workList = workManagementService.findWorkWithLimit(competitionName, phaseName, competitionProcess, submission, limitShowDTO);
	       long count = workManagementService.findCountWithLimit(competitionName, phaseName, competitionProcess, submission, limitShowDTO);
	       result.put("rows", workList);
	       result.put("total", count);
	       System.out.println(count);
	       System.out.println(workList.toString());
	
	       return ResponseUtil.getResEntityForGetAndJson(result);
	   }
	  
	  /**
		 * 得到赛制流程
		 * */
		@RequestMapping(value = "/process", method=RequestMethod.GET)
		public ResponseEntity<String> getProcesses() {
			//这里以后可能要根据登录人的信息来判断，现在先
			
			List<Map<String, Object>> processes = workManagementService.getProcesses();
			Map<String, Object> result = new HashMap<String, Object>();
			result.put("rows", processes);

			return ResponseUtil.getResEntityForGetAndJson(result);
		}
		/**
		 * 得到提交情况
		 * */
		@RequestMapping(value = "/submission", method=RequestMethod.GET)
		public ResponseEntity<String> getSubmission() {
			//这里以后可能要根据登录人的信息来判断，现在先
			
			List<Map<String, Object>> submission = workManagementService.getSubmission();
			Map<String, Object> result = new HashMap<String, Object>();
			result.put("rows", submission);

			return ResponseUtil.getResEntityForGetAndJson(result);
		}
	  
	  
}
	